﻿using AutoMapper;
using BCCommon.Extensions;
using BCCommon.PaymentEnums;
using BCDto.Common.Payment.Payment;
using BCDto.Common.Payment.PaymentRecord;
using BCEntity.Common.Payment.Payment;

namespace BCService.CommonService.Payment
{
    public class AutoMapperProfile : Profile
    {
        public AutoMapperProfile()
        {
            CreateMap<PaymentRecordEntity, PaymentRecordDto>()
                .ForMember(x => x.PaymentChannelId, p => p.MapFrom(s => s.PaymentChannelId.ToString()))
                .IgnoreAllPropertiesWithAnInaccessibleSetter();
            CreateMap<PaymentRecordEntity, PaymentDto>()
                .ForMember(x => x.PayChannelType, p => p.MapFrom(s => s.PaymentChannelId))
                .ForMember(x => x.OriginalAmount, p => p.MapFrom(s => s.Amount))
                .ForMember(x => x.Result, p => p.MapFrom(s => s.Status.AsEnum<PaymentResultType>()))
                .ForMember(x => x.PaidAmount, p => p.MapFrom(s => s.Status == PaymentResultType.Success.ToString() ? s.Amount : 0M))
                .ForMember(x => x.PaidTime, p => p.MapFrom(s => s.SuccessTime))
                .IgnoreAllPropertiesWithAnInaccessibleSetter();
            CreateMap<PaymentRecordUserViewEntity, PaymentRecordUserViewDto>().IgnoreAllPropertiesWithAnInaccessibleSetter();
            CreateMap<PaymentRecordBillViewEntity, PaymentRecordBillViewDto>().IgnoreAllPropertiesWithAnInaccessibleSetter();
        }
    }
}
